<?php
/**
 * 系统栏目管理
 *
 * PHP Version 5.6
 *
 * @author    guanxu <510104561@qq.com>
 * @time      2017/08/11
 */
namespace Admin\Controller;
use Think\Controller;
use Common\Common\ConstantUtil;

Class SysColumnController extends CommonController {

    public function index() {
        $list = M("sys_column")->where(["status"=>ConstantUtil::GLOBAL_TRUE])->order("id desc")->select();
        $this->assign("list",$list);
        $this->display("sys_column/index");
    }

    public function add() {
        $name = I("post.name");
        $data["name"] = $name;
        $data["status"] = ConstantUtil::GLOBAL_TRUE;
        $data["create_time"] = date("Y-m-d H:i:s");
        $result = M("sys_column")->create($data);
        A("index")->header();
        if(empty($result)) {
            $this->error("添加失败!");
        } else {
            $this->success("添加成功!");
        }
    }

    public function addView() {
        $this->display('sys_column/add');
    }

    public function editorView() {
        $id = I("get.id");
        if(empty($id)) return '';
        $list = M("sys_column")->where(["id"=>$id])->find();
        $this->assign("list",$list);
        $this->display('sys_column/editor');
    }

    /**
     * 编辑
     * @return string
     */
    public function editor() {
        $id = I("post.id");
        $name = I("post.name");
        if(empty($id)) return '';
        M("sys_column")->where(["id"=>$id])->save(["name"=>$name]);
        A("index")->header();
        $this->success("修改成功!");

    }
    public function delete() {
        $id = I("post.id");
        if(empty($id)) return '';
        M("sys_column")->where(["id"=>$id])->save(["status"=>ConstantUtil::GLOBAL_FALSE]);
        A("index")->header();
        $this->success("删除成功!");
    }


}